package com.dykj.fireFighting.server.base.enterprise.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.base.enterprise.dto.SafePersonDto;
import com.dykj.fireFighting.api.base.enterprise.entity.SafePerson;
import com.dykj.fireFighting.api.base.enterprise.service.ISafePersonService;
import com.dykj.fireFighting.api.base.enterprise.vo.SafePersonVo;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.base.enterprise.mapper.SafePersonMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;


import java.util.HashMap;
import java.util.Map;

/**
 * 人员信息
 *
 * @Author JacksonTu
 * @Date  2021-06-24 14:58:26
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class SafePersonServiceImpl extends BaseServiceImpl<SafePersonMapper, SafePerson> implements ISafePersonService {


    @Override
    public SafePersonVo getInfoById(String id) {
        return this.baseMapper.getInfoById(id);
    }

    @Override
    public PageVo<SafePersonVo> queryList(SafePersonDto safePersonDto) {
        Map<String, Object> params = new HashMap<>();

        params.put("unitId", safePersonDto.getUnitId());

        if (StringUtils.isNotBlank(safePersonDto.getName())) {
            params.put("name", "%" + safePersonDto.getName() + "%");
        }
        params.put("isFireDrill",safePersonDto.getIsFireDrill());
        params.put("isFireTrain",safePersonDto.getIsFireTrain());
        params.put("beginDate",safePersonDto.getBeginDate());
        params.put("endDate",safePersonDto.getEndDate());
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(safePersonDto.getPage());
        // 设置页大小
        page.setSize(safePersonDto.getLimit());
        return new PageVo<SafePersonVo>(this.baseMapper.queryList(page, params));
    }
}
